<?php
/**
 * 后台登陆
 */
namespace app\modules\controllers;
use yii\web\Controller;
use app\modules\models\Admin;
use Yii;
class PublicController extends Controller{
	public $layout = false;

/**
 * 后台登陆
 * @author   zhuojundu
 */
	public function actionLogin(){
		$model = new Admin;
		if(Yii::$app->request->isPost){
			$post = Yii::$app->request->post();
			if($model->login($post)){
				$this->redirect(['default/index']);
				Yii::$app->end(); 
			}

		}
		return $this->render('login',['model'=>$model]);
	}
/**
 * 发送邮件
 * @author zhuojundu
 */
	public function actionSeekpassword(){
		$this->layout = false;
		$model = new Admin;
		if(Yii::$app->request->isPost){
			$post = Yii::$app->request->post();
			if($model->seekPass($post)){
				Yii::$app->session->setFlash('info','电子邮箱发送成功，请注意查收');
			}
		}
		return $this->render('seekpassword',['model'=>$model]);
	}

/**
 * 退出登陆
 * @author   zhuojundu
 */
	public function actionLogout(){
		Yii::$app->session->removeAll();
		if(!isset(Yii::$app->session['admin']['isLogin'])){
			$this->redirect(['public/login']);
			Yii::$app->end();
		}
		$this->goback();
	}
}